﻿@using MC.RideEvent.Mvc.Models.ViewModel
@model VehiculeViewModel

@{
    var member = Session["CurrentMember"] as MemberViewModel;
}

<script type="text/javascript">
    $(document).ready(function () {

        $("#VehiculeId").kendoDropDownList({
            //optionLabel: "Sélectionnez un modèle...",
            dataTextField: "VehiculeToString",
            dataValueField: "Id",
            dataSource: {
                transport: {
                    read: {
                        async: false,
                        dataType: "json",
                        url: "@Url.Action("VehiculesMember", "VehiculeApi", new {memberId = member.Id})"
                    }
                }
            },
            change: onChangeVehicule
        }).data('kendoDropDownList');

        $("#NumberPlaces").kendoDropDownList({
            //optionLabel: "Sélectionnez un modèle...",
            dataTextField: "text",
            dataValueField: "value",
            dataSource: {
                transport: {
                    read: {
                        async: false,
                        dataType: "json",
                        url: "@Url.Action("VechiculeMemberPlaces", "VehiculeApi")",
                        data : function () {
                            return { vehiculeIdSelected: $("#VehiculeId").val() };
                        }
                    }
                }
            }
        }).data('kendoDropDownList');
    });
    
    function onChangeVehicule(e) {
        var gridNumberPlaces = $("#NumberPlaces").data("kendoDropDownList");
        gridNumberPlaces.dataSource.read();
    }
</script>